
clear
set more off

capture confirm file "Appendix_Results/"
if _rc mkdir "Appendix_Results/"


capture confirm file "Appendix_Results/gphs/"
if _rc mkdir "Appendix_Results/gphs/"



use "Data/Big_Pandemics.dta", clear
gen pandemic=1
drop year
ren endyear year
sort year
merge 1:1 year using "Data/RealRateSince1310.dta"
sort year
replace pandemic=0 if pandemic==.
gen pandemic100k=cond(dead>=100000,pandemic,0)



sort year


keep year W_real* pandemic100k
sort year
reshape long W_real, i(year) j(country) string
replace W_real = log(W_real)*100
egen ctryid = group(country)
sort ctryid year
xtset ctryid year


cap drop b0* se0* b1* se1*  Horizon
cap drop h0* h1* l0* l1*
	gen Horizon = _n-1 if _n<=41
	gen b0=0 if Horizon==0
	gen b1=0 if Horizon==0
	gen h0=0 if Horizon==0
	gen h1=0 if Horizon==0
	gen l0=0 if Horizon==0
	gen l1=0 if Horizon==0
	gen se0=0 if Horizon==0
	gen se1=0 if Horizon==0	
sort ctryid year
xtset ctryid year
tssmooth ma W_real500 = W_real, window(12 1 12) 

gen trend_realwages = W_real500

gen time = year
eststo clear
forv h=1/40 {
gen dtrend_realwages`h' = f`h'.trend_realwages-trend_realwages
xtreg dtrend_realwages`h' pandemic100k  l(1/10).trend_realwages 
eststo
	replace b0  = _b[pandemic100k]                      if Horizon==`h'
	replace se0 = _se[pandemic100k]                     if Horizon==`h'
	replace h0  = _b[pandemic100k]+2*_se[pandemic100k]  if Horizon==`h'
	replace l0  = _b[pandemic100k]-2*_se[pandemic100k]  if Horizon==`h'
	replace h1  = _b[pandemic100k]+1*_se[pandemic100k]  if Horizon==`h'
	replace l1  = _b[pandemic100k]-1*_se[pandemic100k]  if Horizon==`h'
}
esttab , keep(pandemic*)
	cap drop Zero
	gen Zero=0
	twoway ///
		(  rarea h0 l0 Horizon if Horizon~=. , fc(blue)  fi(10) lcolor(white)  lpattern(none)  )  ///
		(  rarea h1 l1 Horizon if Horizon~=. , fc(blue)  fi(20) lcolor(white) lw(none)  lpattern(none)  )  ///
		(  line  Zero    Horizon if Horizon~=. , lc(gray)  lw(med) lp(dash)                     )  ///		
		(  line  b0     Horizon if Horizon~=. , lc(blue)  lw(thick) lp(solid)  ///
				xlab(0(10)40) ylab(, angle(0)) xtitle("Years since pandemic event ended") ///
				ytitle("Percent") ///
				legend( off )) ///
		, title() ///
		xsize(5) ysize(4) scale(1.1) graphregion(color(white)) plotregion(color(white))  scheme(s1color) /// 
		 name(endyear,replace)
	
graph save   Appendix_Results/gphs/FigureA6.gph, replace
graph export Appendix_Results/FigureA6.pdf, replace






